//
//  AIMineAboutMyController.m
//  ZJCLoveBee
//
//  Created by 朱建超 on 16/12/22.
//  Copyright © 2016年 itHeiMa. All rights reserved.
//

#import "AIMineAboutMyController.h"
#import "Masonry.h"
#import "AIMineSharedManger.h"

@interface AIMineAboutMyController ()

@property(nonatomic,weak)UIWebView *webView;

@end

@implementation AIMineAboutMyController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    self.title = @"关于作者";
    
    [self setupUI];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 搭建界面
-(void)setupUI{

    //用户头像
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"author"]];
    
    [self.view addSubview:imageView];
    
    imageView.layer.cornerRadius = 20;
    imageView.layer.masksToBounds = YES;
    
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.view.mas_top).offset(104);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.height.width.mas_equalTo(100);
        
    }];
    
    //用户名字
    UILabel *nameLabel = [[UILabel alloc] init];
    
    nameLabel.text = @"维尼的小熊";
    
    [self.view addSubview:nameLabel];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(imageView.mas_centerX);
        make.top.mas_equalTo(imageView.mas_bottom).offset(20);
        
    }];
    
    //github的button  http://weibo.com/tianzhongtao
    UIButton *githubButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [githubButton setTitle:@"GitHub：http://github.com/ZhongTaoTian" forState:UIControlStateNormal];
    githubButton.titleLabel.font = [UIFont systemFontOfSize:14];
    githubButton.tag = 0;
    
    [self.view addSubview:githubButton];
    
    [githubButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(nameLabel.mas_bottom).offset(30);
        make.left.mas_equalTo(self.view.mas_left).offset(40);
        make.right.mas_equalTo(self.view.mas_right);
        
    }];
    
    UIButton *sinaButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [sinaButton setTitle:@"新浪微博：http://weibo.com/tianzhongtao" forState:UIControlStateNormal];
    sinaButton.titleLabel.font = [UIFont systemFontOfSize:14];
    sinaButton.tag = 1;
    
    [self.view addSubview:sinaButton];
    
    [sinaButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(githubButton.mas_bottom).offset(30);
        make.left.mas_equalTo(githubButton.mas_left);
        make.right.mas_equalTo(githubButton.mas_right);
        
    }];
    
    UIButton *abilityButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [abilityButton setTitle:@"技术博客：http://www.jianshu.com/users/5fe7513c7a57/latest_articles" forState:UIControlStateNormal];
    abilityButton.titleLabel.font = [UIFont systemFontOfSize:14];
    abilityButton.titleLabel.numberOfLines = 0;

    [self.view addSubview:abilityButton];
    abilityButton.tag = 2;
    
    [abilityButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(sinaButton.mas_bottom).offset(30);
        make.left.mas_equalTo(sinaButton.mas_left);
        make.right.mas_equalTo(sinaButton.mas_right);
        
    }];
    
    
    [githubButton addTarget:self action:@selector(getURL:) forControlEvents:UIControlEventTouchUpInside];
    [sinaButton addTarget:self action:@selector(getURL:) forControlEvents:UIControlEventTouchUpInside];
    [abilityButton addTarget:self action:@selector(getURL:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)getURL:(UIButton *)button{

    UIWebView *webView = [[UIWebView alloc] init];
    
    [self.view addSubview:webView];
    
    self.webView = webView;
    
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(64);
        
    }];
    
    //控制放大缩小页面
    self.webView.scalesPageToFit = YES;
    
    
    if (button.tag == 0) {
        
        [self.webView loadRequest:[[AIMineSharedManger sharedInstance] getGitHub]];
        self.title = @"GitHub";
        
    }else if (button.tag == 1){
    
        [self.webView loadRequest:[[AIMineSharedManger sharedInstance] getSina]];
        self.title = @"新浪微博";
        
    }else{
    
        [self.webView loadRequest:[[AIMineSharedManger sharedInstance] getJianShu]];
        self.title = @"简书";
    
    }

}



@end
